package com.api.interceptor;

import java.lang.reflect.Method;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogInterceptor{
	
	private static final Logger logger = LoggerFactory.getLogger(LogInterceptor.class);

	/**
	 * 定义拦截规则：拦截com.xjj.web.controller包下面的所有类中，有@RequestMapping注解的方法。
	 */
	@Pointcut("execution(* com.api.controller..*(..))")
	public void logPointcut() {
	}

	@Before("logPointcut()")
	public void doBefore(JoinPoint joinPoint) {
		
//		 MethodSignature signature = (MethodSignature) joinPoint.getSignature();  
//	     Method method = signature.getMethod(); //获取被拦截的方法  
//	     String methodName = method.getName();
//	     Class<?>[] argsClass = method.getParameterTypes();// 参数类型
//	     Class<? extends Object> targetClass = joinPoint.getTarget().getClass();// 目标类
//	     String targetName = targetClass.getName();
//	     Object[] obj=joinPoint.getArgs();
//	     
//	     logger.info("类："+targetName+"方法："+methodName);
//	     for (int i = 0; i < obj.length; i++) {
//	    	 logger.info(obj[i].toString());
//		}
	}

	/**
	 * 判断一个方法是否需要登录
	 * 
	 * @param method
	 * @return
	 */
	// private boolean isLoginRequired(Method method) {
	// if (!env.equals("prod")) { // 只有生产环境才需要登录
	// return false;
	// }
	//
	// boolean result = true;
	// if (method.isAnnotationPresent(Permission.class)) {
	// result = method.getAnnotation(Permission.class).loginReqired();
	// }
	//
	// return result;
	// }

	// 判断是否已经登录
	private boolean isLogin(HttpServletRequest request) {
		return true;
		/*
		 * String token = XWebUtils.getCookieByName(request, WebConstants.CookieName.AdminToken);
		 * if("1".equals(redisOperator.get(RedisConstants.Prefix.ADMIN_TOKEN+token))){ return true; }else { return false; }
		 */
	}
}
